const { mysql } = require('../qcloud')

module.exports = async (ctx) => {
    var { page, size } = ctx.request.query
    page = page || 0
    size = size || 5
    console.log(`page=${page}------size=${size}`)
    const books = await mysql('books')
        .select('books.*', 'csessioninfo.user_info')
        .join('csessioninfo', 'books.openid', 'csessioninfo.open_id')
        .limit(size)
        .offset(Number(page) * size)
        .orderBy('id', 'desc')
    ctx.state.data = {
        list: books.map(v => {
            let userInfo = JSON.parse(v.user_info)
            // return Object.assign({},v,{
            //   user_info: {
            //     nickName: user_info.nickName
            //   }
            // })
            v.user_info = {
                nickName: userInfo.nickName
            }
            return v
        })
    }
}
